<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
<!--      <el-form-item label="报告地区名称" prop="bgdqmc">-->
<!--        <el-input-->
<!--          v-model="queryParams.bgdqmc"-->
<!--          placeholder="请输入报告地区名称"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="报告卡编号" prop="bgbh">-->
<!--        <el-input-->
<!--          v-model="queryParams.bgbh"-->
<!--          placeholder="请输入报告卡编号"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="填报单位代码" prop="tbdwdm">-->
<!--        <el-input-->
<!--          v-model="queryParams.tbdwdm"-->
<!--          placeholder="请输入填报单位代码"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="填报单位名称" prop="tbdwmc">-->
<!--        <el-input-->
<!--          v-model="queryParams.tbdwmc"-->
<!--          placeholder="请输入填报单位名称"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="死者姓名" prop="szxm">
        <el-input
          v-model="queryParams.szxm"
          placeholder="请输入死者姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="性别(0男 1女 2未知)" prop="xb">-->
<!--        <el-input-->
<!--          v-model="queryParams.xb"-->
<!--          placeholder="请输入性别(0男 1女 2未知)"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="证件类型" prop="zjlx">-->
<!--        <el-input-->
<!--          v-model="queryParams.zjlx"-->
<!--          placeholder="请输入证件类型"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="证件号码" prop="zjhm">
        <el-input
          v-model="queryParams.zjhm"
          placeholder="请输入证件号码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="出生日期" prop="csrq">-->
<!--        <el-date-picker clearable-->
<!--          v-model="queryParams.csrq"-->
<!--          type="date"-->
<!--          value-format="yyyy-MM-dd"-->
<!--          placeholder="请选择出生日期">-->
<!--        </el-date-picker>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="民族" prop="mz">-->
<!--        <el-input-->
<!--          v-model="queryParams.mz"-->
<!--          placeholder="请输入民族"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="生前详细地址" prop="szxxdz">-->
<!--        <el-input-->
<!--          v-model="queryParams.szxxdz"-->
<!--          placeholder="请输入生前详细地址"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="户籍详细地址" prop="hjxxdz" label-width="100">
        <el-input
          v-model="queryParams.hjxxdz"
          placeholder="请输入户籍详细地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="死亡日期" prop="swrq">-->
<!--        <el-date-picker clearable-->
<!--          v-model="queryParams.swrq"-->
<!--          type="date"-->
<!--          value-format="yyyy-MM-dd"-->
<!--          placeholder="请选择死亡日期">-->
<!--        </el-date-picker>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="死亡地点" prop="swdd">-->
<!--        <el-input-->
<!--          v-model="queryParams.swdd"-->
<!--          placeholder="请输入死亡地点"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="可联系的家属姓名" prop="jtxm" label-width="100">
        <el-input
          v-model="queryParams.jtxm"
          placeholder="请输入可联系的家属姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="家属联系电话" prop="jtdh">-->
<!--        <el-input-->
<!--          v-model="queryParams.jtdh"-->
<!--          placeholder="请输入家属联系电话"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['happiness:beHappiness:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['happiness:beHappiness:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['happiness:beHappiness:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['happiness:beHappiness:export']"
        >导出</el-button>
      </el-col>
        <el-col :span="1.5">
<!--          <file-upload :isShowTip="isShowTip" :fileType="fileType" :limit="1" uploadUrl="/system/swxx/importData" v-hasPermi="['happiness:beHappiness:upload']"></file-upload>-->
        </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="swxxList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="报告地区名称" align="center" prop="bgdqmc" />
      <el-table-column label="报告卡编号" align="center" prop="bgbh" width="180"/>
      <el-table-column label="填报单位代码" align="center" prop="tbdwdm" />
      <el-table-column label="填报单位名称" align="center" prop="tbdwmc" width="180"/>
      <el-table-column label="死者姓名" align="center" prop="szxm" />
      <el-table-column label="性别" align="center" prop="xb" />
      <el-table-column label="证件类型" align="center" prop="zjlx" />
      <el-table-column label="证件号码" align="center" prop="zjhm" width="180"/>
      <el-table-column label="出生日期" align="center" prop="csrq" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.csrq, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="民族" align="center" prop="mz" />
      <el-table-column label="生前详细地址" align="center" prop="szxxdz" width="180"/>
      <el-table-column label="户籍详细地址" align="center" prop="hjxxdz" width="180"/>
      <el-table-column label="死亡日期" align="center" prop="swrq" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.swrq, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="死亡地点" align="center" prop="swdd" />
      <el-table-column label="可联系的家属姓名" align="center" prop="jtxm" />
      <el-table-column label="家属联系电话" align="center" prop="jtdh" />
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.status == 0" type="warning">待审核</el-tag>
          <el-tag v-if="scope.row.status == 1" type="success">已审核</el-tag>
          <el-tag v-if="scope.row.status == 2" type="danger">已驳回</el-tag>
    </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" min-width="120" fixed="right">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['happiness:beHappiness:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['happiness:beHappiness:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改死亡信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="110px" >
        <el-form-item label="报告地区名称" prop="bgdqmc">
          <el-input v-model="form.bgdqmc" placeholder="请输入报告地区名称" />
        </el-form-item>
        <el-form-item label="报告卡编号" prop="bgbh">
          <el-input v-model="form.bgbh" placeholder="请输入报告卡编号" />
        </el-form-item>
        <el-form-item label="填报单位代码" prop="tbdwdm">
          <el-input v-model="form.tbdwdm" placeholder="请输入填报单位代码" />
        </el-form-item>
        <el-form-item label="填报单位名称" prop="tbdwmc">
          <el-input v-model="form.tbdwmc" placeholder="请输入填报单位名称" />
        </el-form-item>
        <el-form-item label="死者姓名" prop="szxm">
          <el-input v-model="form.szxm" placeholder="请输入死者姓名" />
        </el-form-item>
        <el-form-item label="性别" prop="xb">
<!--          <el-input v-model="form.xb" placeholder="请输入性别(0男 1女 2未知)" />-->
          <el-select v-model="form.xb" placeholder="请选择">
            <el-option
              v-for="item in sexOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="证件类型" prop="zjlx">
          <el-input v-model="form.zjlx" placeholder="请输入证件类型" />
        </el-form-item>
        <el-form-item label="证件号码" prop="zjhm">
          <el-input v-model="form.zjhm" placeholder="请输入证件号码" />
        </el-form-item>
        <el-form-item label="出生日期" prop="csrq">
          <el-date-picker clearable
            v-model="form.csrq"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择出生日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="民族" prop="mz">
          <el-input v-model="form.mz" placeholder="请输入民族" />
        </el-form-item>
        <el-form-item label="生前详细地址" prop="szxxdz">
          <el-input v-model="form.szxxdz" placeholder="请输入生前详细地址" />
        </el-form-item>
        <el-form-item label="户籍详细地址" prop="hjxxdz">
          <el-input v-model="form.hjxxdz" placeholder="请输入户籍详细地址" />
        </el-form-item>
        <el-form-item label="死亡日期" prop="swrq">
          <el-date-picker clearable
            v-model="form.swrq"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择死亡日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="死亡地点" prop="swdd">
          <el-input v-model="form.swdd" placeholder="请输入死亡地点" />
        </el-form-item>
        <el-form-item label="可联系的家属姓名" prop="jtxm">
          <el-input v-model="form.jtxm" placeholder="请输入可联系的家属姓名" />
        </el-form-item>
        <el-form-item label="家属联系电话" prop="jtdh">
          <el-input v-model="form.jtdh" placeholder="请输入家属联系电话" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import { listSwxx, getSwxx, delSwxx, addSwxx, updateSwxx } from "@/api/system/swxx";
// import fileUpload from '@/components/FileUpload/index.vue'
export default {
  name: "Swxx",
  // components:{
  //   fileUpload,
  // },
  data() {
    return {
      isShowTip:true,
      fileType:['xls','xlsx'],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 死亡信息表格数据
      swxxList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        bgdqmc: null,
        bgbh: null,
        tbdwdm: null,
        tbdwmc: null,
        szxm: null,
        xb: null,
        zjlx: null,
        zjhm: null,
        csrq: null,
        mz: null,
        szxxdz: null,
        hjxxdz: null,
        swrq: null,
        swdd: null,
        jtxm: null,
        jtdh: null,
        status: null,
      },
      // 表单参数
      form: {},
      sexOptions: [{
        value: '0',
        label: '男'
      }, {
        value: '1',
        label: '女'
      }, {
        value: '2',
        label: '未知'
      }],
      // 表单校验
      rules: {
        bgdqmc: [
          { required: true, message: "报告地区名称不能为空", trigger: "blur" }
        ],
        bgbh: [
          { required: true, message: "报告卡编号不能为空", trigger: "blur" }
        ],
        tbdwdm: [
          { required: true, message: "填报单位代码不能为空", trigger: "blur" }
        ],
        tbdwmc: [
          { required: true, message: "填报单位名称不能为空", trigger: "blur" }
        ],
        szxm: [
          { required: true, message: "死者姓名不能为空", trigger: "blur" }
        ],
        xb: [
          { required: true, message: "性别不能为空", trigger: "change" }
        ],
        zjlx: [
          { required: true, message: "证件类型不能为空", trigger: "blur" }
        ],
        zjhm: [
          { required: true, message: "证件号码不能为空", trigger: "blur" }
        ],
        csrq: [
          { required: true, message: "出生日期不能为空", trigger: "blur" }
        ],
        mz: [
          { required: true, message: "民族不能为空", trigger: "blur" }
        ],
        szxxdz: [
          { required: true, message: "生前详细地址不能为空", trigger: "blur" }
        ],
        hjxxdz: [
          { required: true, message: "户籍详细地址不能为空", trigger: "blur" }
        ],
        swrq: [
          { required: true, message: "死亡日期不能为空", trigger: "blur" }
        ],
        swdd: [
          { required: true, message: "死亡地点不能为空", trigger: "blur" }
        ],
        status: [
          { required: true, message: "状态(0-待审核 1-已审核 2-已驳回)不能为空", trigger: "change" }
        ],
        delFlag: [
          { required: true, message: "删除标志(0-未删除 1-已删除)不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询死亡信息列表 */
    getList() {
      this.loading = true;
      listSwxx(this.queryParams).then(response => {
        this.swxxList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        bgdqmc: null,
        bgbh: null,
        tbdwdm: null,
        tbdwmc: null,
        szxm: null,
        xb: null,
        zjlx: null,
        zjhm: null,
        csrq: null,
        mz: null,
        szxxdz: null,
        hjxxdz: null,
        swrq: null,
        swdd: null,
        jtxm: null,
        jtdh: null,
        status: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        delFlag: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加死亡信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getSwxx(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改死亡信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateSwxx(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addSwxx(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除死亡信息编号为"' + ids + '"的数据项？').then(function() {
        return delSwxx(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/swxx/export', {
        ...this.queryParams
      }, `swxx_${new Date().getTime()}.xlsx`)
    },
    /* 下载模板 */
    handleExportExample() {
      this.download('system/swxx/importTemplate', {
      }, `GA_导入模板.xlsx`)
    },
  }
};
</script>
